<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="78px">
      <el-form-item label="姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工号" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入完整工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="科室" prop="userDept">
        <el-select v-model="queryParams.userDept" placeholder="请选择">
          <el-option
            v-for="item in dept"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="人员类别" prop="userLeibie">
        <el-select v-model="queryParams.userLeibie" placeholder="请选择">
          <el-option
            v-for="item in userLeibieList"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="岗位类别" prop="userLeixing">
        <el-select v-model="queryParams.userLeixing" placeholder="请选择">
          <el-option
            v-for="item in postLeibieList"
            :key="item.positionId"
            :label="item.jobCategory"
            :value="item.jobCategory"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['train:admin:export']"
              >导出所选项
              </el-button>
            </el-col>-->

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportAll"
          v-hasPermi="['train:admin:exportAll']"
        >导出
        </el-button>
      </el-col>

    </el-row>

    <el-table border fit v-loading="loading" :data="trainList" @selection-change="handleSelectionChange"
              @filter-change="filterChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
<!--      <el-table-column label="工号" width="75" align="center" prop="userId"/>-->
      <el-table-column label="科室" width="115" align="center" prop="userDept"
      >
      </el-table-column>
      <el-table-column label="姓名" width="95" align="center" prop="userName"/>
      <el-table-column label="人员类别" width="115" align="center" prop="userLeibie"/>
      <el-table-column label="岗位类别" width="115" align="center" prop="userLeixing"/>
      <el-table-column label="课程名称" width="115" align="center" prop="trainName"/>
      <el-table-column label="培训类型" width="115" align="center" prop="trainType"/>
      <el-table-column label="培训学时" width="85" align="center" prop="trainHours"/>
      <el-table-column label="培训时间" align="center" prop="trainTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.trainTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="课程内容" width="125" align="center" prop="trainContent"/>
      <el-table-column label="备注" width="125" align="center" prop="trainRemarks"/>
      <el-table-column label="状态" align="center" prop="trainIdea">
        <template slot-scope="{row}">
          <el-tag
            type="info"
            v-show="row.trainIdea===0"
          >
            未审批
          </el-tag>
          <el-tag
            type="success"
            v-show="row.trainIdea===1"
          > 确定
          </el-tag>
          <el-tag
            type="danger"
            v-show="row.trainIdea===2"
          > 未发生
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="handleView(scope.row)"
            v-hasPermi="['train:master:query']"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
import {
  adminExport, getDept,
  masterListTrain
} from '@/api/train/train'
import { map } from 'core-js/internals/array-iteration'

export default {
  name: 'trainTotal',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 培训表格数据
      trainList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        trainId: null,
        userId: null,
        userDept: null,
        userLeibie:null,
        userLeixing:null
      },
      //
      dept: [],
      //人员类别下拉菜单
      userLeibieList:[],
      //岗位类别下拉菜单
      postLeibieList:[]
    }
  },
  created() {
    this.getList()
    this.pushDept()
  },
  methods: {
    //
    pushDept() {
      getDept().then(response => {
        this.dept = response.data.deptList
        this.postLeibieList=response.data.postName
        this.userLeibieList=response.data.roleName
      })

    },
    // 表单重置
    reset() {
      this.queryParams = {
        trainId: null,
        userId: null,
        userDept: null
      }
    },
    /** 查询培训列表 */
    getList() {
      this.loading = true
      masterListTrain(this.queryParams).then(response => {
        this.trainList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.trainId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 查看按钮跳转操作 */
    handleView(row) {
      this.$router.push({ path: '/ViewTrainExcel', query: { trainId: row.trainId } })
    },

    /** 导出按钮操作 */
    handleExport() {
      adminExport(this.ids)
    },

    handleExportAll() {
      this.download('train/adminExportAll', {
        ...this.queryParams
      }, `培训记录统计${new Date().getTime()}.xlsx`)
    },
    /* table表格数据过滤 */
    filterChange(val) {
      //参考https://blog.csdn.net/m0_59462557/article/details/123711142
      this.reset()
      //filterChange filters取值
      const vv = val[Object.keys(val)[0]]
      const v = vv[0]
      this.queryParams.userDept = v
      this.getList()
    }

  }
}
</script>
